import {
  ajax,
  src,
  util
} from "../../utils/util.js";
const app = getApp()

let isIphoneX = app.globalData.isIphoneX;
Page({

  data: {
    userInfo:"",
    details:"",
    uqid:"",
    markerId:"",
    isiphone: isIphoneX,
    lxkf: 0,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
   
    autoplay: false,
    currentbg: 1,

    current: 0,
    navData: [{
      name: "客服", //文本
      index: 0, //是否是当前页，0不是  1是
      style: 3, //样式
      ico: 'kefu', //不同图标
      fn: 'gotokefu' //对应处理函数
    }, {
      name: "",
      index: "",
      style: 1,
      ico: '',
      fn: 'gotoScan',
    }, {
      name: "意见反馈",
      index: 1,
      style: 3,
      ico: 'fankui',
      fn: 'gotofankui'
    },],
    did:""
  },
  onLoad:function(options){
    var uqid=wx.getStorageSync("uqid");
    var markerId=options.markerId
    this.setData({
      uqid: uqid,
      markerId: markerId
    });
    this.getpetdetail()

    this.getInfofirst(uqid);
  },


  onshow: function (options){
    var uqid = wx.getStorageSync("uqid");
    var markerId = options.markerId
    this.setData({
      uqid: uqid,
      markerId: markerId
    });
    this.getpetdetail()
    this.getInfofirst(uqid);
  },

  getInfofirst: function (uqid) {
    console.log(uqid)
    ajax("/api/user/user_info", {
      data: {
        uqid: uqid,
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
    }, res => {
      console.log(res);
      if (res.error == 0) {
        console.log("set 1 次")
        this.setData({
          userInfo: res.data,
          uqid: uqid,
          islogin: 1,
        });
        if (res.data.phone) {
          this.setData({
            tel: res.data.phone
          });
          wx.setStorageSync("tel", res.data.phone)
        }

      }
    })
  },

  getpetdetail:function(){
    ajax('/api/index/pet_cabinet_show', {
      data: {
        uqid:this.data.uqid,
        id:this.data.markerId
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
      method: 'get'
    }, res => {
      console.log(res)
      if (res.error == 0) {
        this.setData({
          details: res.data
         
        });
      } 
    })
  },

  tuichutanchuang: function () {
    this.setData({
      lxkf: 0
    });
  },

  phoneCall: function (e) {
    var tel = e.currentTarget.dataset.tel;

    if (wx.getStorageSync("uqid")) {
      ajax("/api/user/service", {
        data: {
          uqid: this.data.uqid,
        },
        header: {
          'Accept': 'application/json', // 默认值
        },
        method: 'get'
      }, res => {
        console.log(res);
        if (res.error == 0) {
          this.setData({
            kftel: res.data.admin_phone
          })
          wx.makePhoneCall({
            phoneNumber: res.data.admin_phone //仅为示例，并非真实的电话号码
          })
        }
      })
    } else {
      wx.showToast({
        title: '请先授权！',
        icon: 'none',
        duration: 2000
      })

    }
  },
 

  whenchange: function (e) {
    // console.log(e.detail.current)
    var current = e.detail.current + 1
    this.setData({
      currentbg: current
    })
  }
  , 
  gotokefu: function () {
    this.setData({
      lxkf: 1
    });
    this.setData({
      current: 0
    });
  },
  toseletlocalapp:function(e){
    var latitude = Number(e.currentTarget.dataset.latitude);
    var longitude = Number(e.currentTarget.dataset.longitude);
    // console.log(latitude)
    wx.openLocation({
      latitude,
      longitude,
      scale: 18
    })
  },
  gotofankui: function () {
    var pcid=this.data.details.id
    wx.navigateTo({
      url: '/pages/feedback/feedback?pcid='+pcid,
    })
    this.setData({
      current: 1
    });
  },

  gotoScan: function () {
    this.tonext()
    
  },
  tonext: function () {
    var isfirst = this.data.userInfo.is_prompt
    if (isfirst == 1) {
      wx.navigateTo({
        url: '/pages/procedure/procedure',
      })
    } else {
      var _this = this;

      wx.scanCode({
        success: (res) => {
          var result = res.result;
          _this.setData({
            did: result,
          })

          wx.navigateTo({
            url: '/pages/unlocking/unlocking?did=' + this.data.did,
          })
        }
      })
    }
  },

})